$(function() {
    var orderId = wsCommon.getUrlParam('orderId');

    var paysuccess = {
        checkorder: function() {
            $('[data-role="checkOrder"]').on('click', function() {
                window.location.href = './member-orderdetail.html?orderId=' + orderId;
            })
        },
        initData: function() {
            $.ajax({
			    url: wsCommon.host + '/api/orders/queryByOrderId',
			    dataType: wsCommon.jsonType,
				data: {
					orderId: orderId
				},
			    success: function(res) {
					if(res.code == 1) {
						if(res.result) {
                            var orders = res.data.orders;
                            var itemsList = orders.itemsList;

                            $('[data-role="orderid"]').html(orders.orderId);
                            $('[data-role="money"]').html('¥' + orders.finalAmount);

                            var tpl = '';
                            $.each(itemsList, function(index, item) {
                                tpl += '<tr>\
                                            <td style="line-height:30px;">'+item.orderId+'</td>\
                                            <td style="line-height:30px;color:red;">¥'+orders.finalAmount+'</td>\
                                            <td style="line-height:30px;">'+item.nums+'</td>\
                                            <td style="line-height:30px;">'+orders.shipArea+orders.shipAddr+'(收货人：'+orders.shipName+' 手机：'+orders.shipMobile+') '+orders.shipTime+'</td>\
                                        </tr>';
                            })

                            $('[data-role="cartList"]').html(tpl);

                        } else {
                            wsCommon.setCookie('go_back_link', window.location.href);
							window.location.href = './passport-login.html';
                        }
                    }
                },
                error: function() {

                }
            })
        },
        init: function() {
            this.initData();
            this.checkorder();
        }
    }

    paysuccess.init();
})
